package com.tianji.learning.mq;


import com.tianji.api.dto.trade.OrderBasicDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.enums.PointsRecordType;
import com.tianji.learning.mq.message.PointsMessage;
import com.tianji.learning.service.ILearningLessonService;
import com.tianji.learning.service.IPointsRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class LearningPointsListener {
    private final IPointsRecordService pointsRecordService;

    //交换机，路由器，key
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "sign.points.queue", durable = "true"),
                    exchange = @Exchange(value = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
                    key = MqConstants.Key.SIGN_IN
            )
    )
    public void listenLessonKey(PointsMessage message) {
        //1.判断
        if (message == null) {
            log.error("message为空");
            return;
        }
        //2.调用业务
        pointsRecordService.addPointsRecord(message, PointsRecordType.SIGN);
    }
}
